package com.chrray.position.controller.web.sysUser;

import com.chrray.position.entity.position.SysRole;
import com.chrray.position.pojo.dto.auth.*;
import com.chrray.position.service.auth.SysJurisdictionService;
import com.chrray.position.util.result.PageBean;
import com.chrray.position.util.result.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

;import javax.annotation.Resource;


/**
 * Created by IntelliJ IDEA.
 *
 * @Author: Q
 * @Created: 2021/1/12 19:54
 * @Description:
 * @Versions: 1.0
 */

@RestController

@RequestMapping("/api/web/role")
@Api(value  = "角色管理", tags  = "角色管理")

@Slf4j
@ResponseBody
public class RoleController {

    @Resource
    private SysJurisdictionService sysJurisdictionService;

    @PostMapping("/roleFind")
    @ApiOperation(value =  "角色列表")
    public ResponseResult<PageBean<SysRole>> roleFind(@RequestBody RoleListDto dto) {
        return sysJurisdictionService.roleFind(dto);
    }

    @PostMapping("/roleAdd")
    @ApiOperation(value =  "角色添加")
    @ResponseBody
    public ResponseResult roleAdd(@RequestBody RoleInsertDto RoleDto) {
        return sysJurisdictionService.roleInsert(RoleDto);
    }

    @PostMapping("/roleUpdate")
    @ApiOperation(value =  "角色修改")
    @ResponseBody
    public ResponseResult roleUpdate(@RequestBody RoleUpdateDto RoleDto) {
        return sysJurisdictionService.roleUpdate(RoleDto);
    }

    @PostMapping("/roleUpdateMenu")
    @ApiOperation(value =  "权限设置")
    @ResponseBody
    public ResponseResult roleUpdateMenu(@RequestBody RoleDto RoleDto) {
        return sysJurisdictionService.roleUpdateMenu(RoleDto);
    }

    @GetMapping("/roleDelete")
    @ApiOperation(value =  "角色删除")
    public ResponseResult roleDelete(@RequestParam(value = "id") Long id) {
        return sysJurisdictionService.roleDelete(id);
    }

    @GetMapping("/roleMenuDetail")
    @ApiOperation(value =  "角色详情（含权限）")
    public ResponseResult<RoleMenuDto> roleMenuDetail( @RequestParam(value = "id") Long id) {
        return sysJurisdictionService.roleMenuDetail(id);
    }

    @GetMapping("/roleDetail")
    @ApiOperation(value =  "角色详情（不含权限）")
    public ResponseResult<SysRole> roleDetail(@RequestParam(value = "id") Long id) {
        return sysJurisdictionService.roleDetail(id);
    }

    @ApiOperation(value  = "启用。禁用")
    @PostMapping(value = "/upOrDownRole")
    public ResponseResult upOrDownRole( @RequestBody AllRoleUpRequest sysUser) {
        return sysJurisdictionService.upOrDownRole(sysUser);
    }
}

